package eu.boss.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 * Describes a list of teams. This list will be lengh 3 (shadow, hunter, neutral)
 * @author Arnaud
 *
 */

public class TeamList implements Serializable{

	private static final long serialVersionUID = -4815977245001543733L;
	private List<Team> teamList;

	public TeamList(TeamList tList)
	{
		teamList = new ArrayList<Team>();
		for (int i=0; i<tList.getTeamList().size(); i++)
		{
			teamList.add(tList.getTeamList().get(i));
		}
	}
	
	public TeamList(){}

	@JsonIgnore
	public TeamList(String s){
		teamList = new ArrayList<Team>();
		Team shadow = new Team(TeamType.SHADOW, 0, 0);
		Team neutral = new Team(TeamType.NEUTRAL, 0, 0);
		Team hunter = new Team(TeamType.HUNTER, 0, 0);
		teamList.add(shadow);
		teamList.add(hunter);
		teamList.add(neutral);
	}
	
	public List<Team> getTeamList() {
		return teamList;
	}

	public void setPlayers(List<Team> tList) {
		this.teamList = tList;
	}
	
	/**
	 * Sort playerlist by ratio
	 */
	public void sort()
	{
		Collections.sort(teamList);
	}
	
	
	@JsonIgnore
	public Team getTeam(TeamType t){
		for (int i=0; i<3; i++){
			if (t==teamList.get(i).getTeam())
				return teamList.get(i);
		}
		return null;
	}
	
	/**
	 * reinitialize every single player of the list
	 */
	@JsonIgnore
	public void reinitList(){
		for (int i=0; i<teamList.size(); i++)
		{
			teamList.get(i).reInit();
		}
	}
}
